package tk.mybatis.web.utils;

import java.io.Serializable;

/**
 * @author: chenhs
 * @date: Created in 17:31 2020/4/4
 **/
public class PageInfo implements Serializable {

    private static final long serialVersionUID = -3365478708088678139L;

    /**当前表中总条目数量*/
    private int totalNumber;
    /**当前页位置*/
    private int currentPage;

    /**总页数*/
    private int totalPage;
    /**页面大小*/
    private int pageSize = 3;

    /**检索起始位置*/
    private int startIndex;
    /**检索的总数目*/
    private int totalSelect;

    public int getTotalNumber() {
        return totalNumber;
    }

    public void setTotalNumber(int totalNumber) {
        this.totalNumber = totalNumber;
        //计算
        count();
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getStartIndex() {
        return startIndex;
    }

    public void setStartIndex(int startIndex) {
        this.startIndex = startIndex;
    }

    public int getTotalSelect() {
        return totalSelect;
    }

    public void setTotalSelect(int totalSelect) {
        this.totalSelect = totalSelect;
    }

    /**
     * 计算
     */
    public void count() {
        int totalPageTmp = this.totalNumber / this.pageSize;
        int plus = (this.totalNumber % this.pageSize) == 0 ? 0 : 1;
        totalPageTmp = totalPageTmp + plus;
        if (totalPageTmp <= 0) {
            totalPageTmp = 1;
        }
        this.totalPage = totalPageTmp;

        if (this.totalPage < this.currentPage) {
            this.currentPage = this.totalPage;
        }

        if (this.currentPage < 1) {
            this.currentPage = 1;
        }
        //起始位置等于之前所有页面数乘以页面大小
        this.startIndex = (this.currentPage - 1)* pageSize;
        //检索数量等于页面大小
        this.totalSelect = this.pageSize;
    }
}
